<template>
	<view >
		<uni-section title="企业信息完善" type="line"></uni-section>
		<view class="p15">
			<uni-forms label-position="top" ref="baseForm" :modelValue="form" label-width="120">
				<uni-forms-item label="名称:" required>
					<uni-easyinput v-model="form.full_name" placeholder="请输入企业名称" />
				</uni-forms-item>
				<uni-forms-item label="规模:">
					<uni-data-select v-model="form.scale" :localdata="range"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="地区:">
					<picker @change="onRegionChange" :value="form.region" mode="region">
						<slot>
							<div class="region">
								{{form.province}} - {{form.city}} - {{form.areas}}
							</div>
						</slot>
					</picker>
				</uni-forms-item>
				<uni-forms-item label="地址:">
					<uni-easyinput v-model="form.address" placeholder="请输入企业地址" />
				</uni-forms-item>
				<uni-forms-item label="介绍:">
					<uni-easyinput type="textarea" v-model="form.introduction" placeholder="请输入介绍" />
				</uni-forms-item>
				<uni-forms-item label="企业福利:">
					<uni-data-checkbox v-model="form.welfares" multiple :localdata="welfares" />
				</uni-forms-item>
				<uni-forms-item label="法定代表人:">
					<uni-easyinput v-model="form.legal_person" placeholder="请输入法定代表人" />
				</uni-forms-item>
				<uni-forms-item label="注册资本:">
					<uni-easyinput v-model="form.registered_capital" placeholder="请输入注册资本" />
				</uni-forms-item>
				<uni-forms-item label="成立日期:">
					<uni-datetime-picker type="date" return-type="timestamp" v-model="form.registered_date"/>
				</uni-forms-item>
				<uni-forms-item label="经营范围:">
					<uni-easyinput type="textarea" v-model="form.licence" placeholder="请输入经营范围" />
				</uni-forms-item>
			</uni-forms>
			<button class="default-button" @click="save()">提交</button>
		</view>
		
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="success" cancelText="取消" confirmText="去发布" title="通知" content="保存成功,是否去发布职位" @confirm="confirmPush"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					log:'https://xinzhu-1301398555.cos.ap-shanghai.myqcloud.com/wxapp/company-logo.png',
					full_name:'',
					scale:0,
					province:'请选择',
					city:'请选择',
					areas:'请选择',
					address:'',
					introduce:'',
					welfares:[],
					region:[],
					legal_person:'',
					registered_capital:'',
					registered_date:'',
					licence:''
				},
				logo:{name:"company-logo.png",extname:"png",url:"https://xinzhu-1301398555.cos.ap-shanghai.myqcloud.com/wxapp/company-logo.png"},
				welfares:[],
				range:[],
				array:[]
			}
		},
		onShow() {
			this.range = this.$func.map_arr(this.$func.scale)
		},
		onLoad() {
			this.onGetData()
		},
		methods: {
			save(){
				let _this = this
				_this.$refs.alertDialog.open()
				if(!this.form.full_name){
					uni.showToast({title: '请输入企业名称',icon: 'error',duration: 2000})
					return;
				}
				this.form.welfare = JSON.stringify(this.form.welfares)
				this.$request_api('applet_api/recruit_company','POST',this.form).then(res => {
					if(res.code == 200){
						
					}
				}).catch(err => {
					console.log(err)
				})
			},
			onGetData(){
				let _this = this
				this.$request_api('applet_api/recruit_company_info','POST',{}).then(res => {
					if(res.data.id){
						_this.form = res.data
						_this.form.scale_name = _this.$func.scale[res.data.scale]
						_this.form.welfares = res.data.welfare ? JSON.parse(res.data.welfare) : []
					}
					
					_this.welfares = _this.$func.map_uniapp_arr(res.welfare)
				}).catch(err => {
					console.log(err)
				})
			},
			confirmPush(e){
				let _this = this
				uni.navigateTo({
					url: '/user/recruit/recruit'
				});
			},
			onRegionChange(e){
				let _this = this
				_this.form.province = e.detail.value[0],
				_this.form.city = e.detail.value[1],
				_this.form.areas = e.detail.value[2]
			},
		}
	}
</script>

<style>
.region{border: 1px solid #e5e5e5;font-size: 12px;height: 35px;line-height: 35px;padding-left: 8px;color: #6a6a6a;}
</style>
